Improve positioning of keyboard-activated menus with Xinerama.
authorMatthias Clasen <maclas@gmx.de>
Tue, 6 Jul 2004 06:02:57 +0000 (06:02 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 6 Jul 2004 06:02:57 +0000 (06:02 +0000)
Tue Jul  6 02:00:28 2004  Matthias Clasen  <maclas@gmx.de>

* gtk/gtkfilechooserdefault.c (popup_position_func):
* gtk/gtkentry.c (popup_position_func):
* gtk/gtktextview.c (popup_position_func): Improve positioning
of keyboard-activated menus with Xinerama.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkentry.c
gtk/gtkfilechooserdefault.c
gtk/gtktextview.c

index 1b0adc35b0556249bc447e6c3fa30ab4431797d1..71369b76811796cdcfd01e4ccc2e45c7884630aa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Jul  6 02:00:28 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkfilechooserdefault.c (popup_position_func): 
+       * gtk/gtkentry.c (popup_position_func): 
+       * gtk/gtktextview.c (popup_position_func): Improve positioning
+       of keyboard-activated menus with Xinerama.
+
 Tue Jul  6 00:29:03 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkuimanager.c (do_updates): 
index 1b0adc35b0556249bc447e6c3fa30ab4431797d1..71369b76811796cdcfd01e4ccc2e45c7884630aa 100644 (file)
@@ -1,3 +1,10 @@
+Tue Jul  6 02:00:28 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkfilechooserdefault.c (popup_position_func): 
+       * gtk/gtkentry.c (popup_position_func): 
+       * gtk/gtktextview.c (popup_position_func): Improve positioning
+       of keyboard-activated menus with Xinerama.
+
 Tue Jul  6 00:29:03 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkuimanager.c (do_updates): 
index 1b0adc35b0556249bc447e6c3fa30ab4431797d1..71369b76811796cdcfd01e4ccc2e45c7884630aa 100644 (file)
@@ -1,3 +1,10 @@
+Tue Jul  6 02:00:28 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkfilechooserdefault.c (popup_position_func): 
+       * gtk/gtkentry.c (popup_position_func): 
+       * gtk/gtktextview.c (popup_position_func): Improve positioning
+       of keyboard-activated menus with Xinerama.
+
 Tue Jul  6 00:29:03 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkuimanager.c (do_updates): 
index 1b0adc35b0556249bc447e6c3fa30ab4431797d1..71369b76811796cdcfd01e4ccc2e45c7884630aa 100644 (file)
@@ -1,3 +1,10 @@
+Tue Jul  6 02:00:28 2004  Matthias Clasen  <maclas@gmx.de>
+
+       * gtk/gtkfilechooserdefault.c (popup_position_func): 
+       * gtk/gtkentry.c (popup_position_func): 
+       * gtk/gtktextview.c (popup_position_func): Improve positioning
+       of keyboard-activated menus with Xinerama.
+
 Tue Jul  6 00:29:03 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtkuimanager.c (do_updates): 
index ff9919870ada3baa3b996840c9440ed5d3e63c4c..2a7ec896a8cb21ca6d8350e79916b7a70604692f 100644 (file)
@@ -4150,18 +4150,26 @@ popup_position_func (GtkMenu   *menu,
   GtkWidget *widget = GTK_WIDGET (entry);
   GdkScreen *screen = gtk_widget_get_screen (widget);
   GtkRequisition req;
+  gint monitor_num;
+  GdkRectangle monitor;
   
   g_return_if_fail (GTK_WIDGET_REALIZED (entry));
 
-  gdk_window_get_origin (widget->window, x, y);      
-
+  gdk_window_get_origin (widget->window, x, y); 
+     
   gtk_widget_size_request (entry->popup_menu, &req);
   
   *x += widget->allocation.width / 2;
   *y += widget->allocation.height;
 
-  *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
-  *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
+  monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
+  gtk_menu_set_monitor (menu, monitor_num);
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+  *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
+  *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
+
+  *push_in = FALSE;
 }
 
 
index 19708c7d1d9ed0d4e73b0261f5ea08c67031a670..9d690f24a2b4cfc5d622526d0f0f935c1cb161a4 100644 (file)
@@ -2713,28 +2713,57 @@ file_list_build_popup_menu (GtkFileChooserDefault *impl)
                                     G_CALLBACK (show_hidden_toggled_cb), impl);
 }
 
+static void
+popup_position_func (GtkMenu   *menu,
+                     gint      *x,
+                     gint      *y,
+                     gboolean  *push_in,
+                     gpointer  user_data)
+{
+  GtkWidget *widget = GTK_WIDGET (user_data);
+  GdkScreen *screen = gtk_widget_get_screen (widget);
+  GtkRequisition req;
+  gint monitor_num;
+  GdkRectangle monitor;
+  
+  g_return_if_fail (GTK_WIDGET_REALIZED (widget));
+
+  gdk_window_get_origin (widget->window, x, y);      
+
+  gtk_widget_size_request (GTK_WIDGET (menu), &req);
+  
+  *x += (widget->allocation.width - req.width) / 2;
+  *y += (widget->allocation.height - req.height) / 2;
+
+  monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
+  gtk_menu_set_monitor (menu, monitor_num);
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+  *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
+  *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
+
+  *push_in = FALSE;
+}
+
 static void
 file_list_popup_menu (GtkFileChooserDefault *impl,
                      GdkEventButton        *event)
 {
-  int button;
-  guint32 timestamp;
-
+  file_list_build_popup_menu (impl);
   if (event)
-    {
-      button = event->button;
-      timestamp = event->time;
-    }
+    gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
+                   NULL, NULL, NULL, NULL,
+                   event->button, event->time);
   else
     {
-      button = 0;
-      timestamp = GDK_CURRENT_TIME;
+      gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
+                     NULL, NULL, 
+                     popup_position_func, impl->browse_files_tree_view,
+                     0, GDK_CURRENT_TIME);
+      gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->browse_files_popup_menu), 
+                                  FALSE);
     }
 
-  file_list_build_popup_menu (impl);
-  gtk_menu_popup (GTK_MENU (impl->browse_files_popup_menu),
-                 NULL, NULL, NULL, NULL,
-                 button, timestamp);
 }
 
 /* Callback used for the GtkWidget::popup-menu signal of the file list */
index 2c649ca4a0e5f6e25f2fe8dcbb1a4166171ecf3b..84763ca3ba872797bba471efa3442e6ff6c07f2f 100644 (file)
@@ -6790,7 +6790,9 @@ popup_position_func (GtkMenu   *menu,
   GtkTextIter iter;
   GtkRequisition req;      
   GdkScreen *screen;
-  
+  gint monitor_num;
+  GdkRectangle monitor;
+      
   text_view = GTK_TEXT_VIEW (user_data);
   widget = GTK_WIDGET (text_view);
   
@@ -6832,13 +6834,19 @@ popup_position_func (GtkMenu   *menu,
       *x = root_x + (widget->allocation.width / 2 - req.width / 2);
       *y = root_y + (widget->allocation.height / 2 - req.height / 2);      
     }
-
+  
   /* Ensure sanity */
   *x = CLAMP (*x, root_x, (root_x + widget->allocation.width));
   *y = CLAMP (*y, root_y, (root_y + widget->allocation.height));
 
-  *x = CLAMP (*x, 0, MAX (0, gdk_screen_get_width (screen) - req.width));
-  *y = CLAMP (*y, 0, MAX (0, gdk_screen_get_height (screen) - req.height));
+  monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
+  gtk_menu_set_monitor (menu, monitor_num);
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+  *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
+  *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
+
+  *push_in = FALSE;
 }
 
 typedef struct